<template>
  <div class="user-dialog">
    <el-dialog :title="formTitle" :visible.sync="visible" height="700px" width="80%" :close-on-click-modal=false
               @close="dialogClose">
      <el-form ref="plcDeviceForm" :model="dataForm" :label-width="formLabelWidth">
        <el-form-item label="设备编号">
          <el-input v-model="dataForm.device_no"></el-input>
        </el-form-item>
        <el-form-item label="设备名称">
          <el-input v-model="dataForm.device_name"></el-input>
        </el-form-item>
        <el-form-item label="行政区划">
          <el-input v-model="dataForm.dtu_code"></el-input>
        </el-form-item>
        <el-form-item label="地址">
          <el-input v-model="dataForm.dtu_addr"></el-input>
        </el-form-item>
        <el-form-item label="监控地址">
          <el-input v-model="dataForm.video_address"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="reset">重 置</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>

  </div>

</template>

<script>


  export default {
    name: "index",
    methods: {
      setForm(rowForm) {
        let me = this;
        this.visible = true;
        if (rowForm) {
          rowForm['action_type'] = 'plcDeviceUpdate';
          this.dataForm = rowForm;
        } else {
          this.dataForm['action_type'] = 'plcDeviceAdd';
          this.dataForm['enterprise_id'] =  me.$parent.$route.params.enterprise_id;
        }
      },
      reset() {
        this.dataForm = {
          device_no: null,
          dtu_addr: null,
          dtu_code: null,
          device_name: null,
          video_address:null
        };
      },
      submit() {
        let me = this;
        this.$axios.post('deviceRoutes',me.dataForm).then(function () {
          me.visible = false;
          me.$parent.queryData();
        });
      },
      dialogClose() {
        this.reset();
      }
    },
    data() {
      return {
        dataForm : {
          device_no: null,
          dtu_addr: null,
          dtu_code: null,
          device_name: null,
          video_address:null
        },
        visible: false,
        formTitle: '设备窗口',
        formLabelWidth: '120px'
      }
    }
  }
</script>

<style lang="scss">
  .user-dialog {
    .el-dialog__header {
      padding: 20px 20px 10px;
      background-color: #40c9c6;
    }
    .el-dialog__title {
      line-height: 24px;
      font-size: 18px;
      text-align: left;
      font-weight: bold;
      color: #f1fdff;
    }
  }
</style>
